<template>
	<view class="page">
		<view class="name2">
			<text class="name2_1">{{info.sname}} {{info.dir}}</text>
			<view class="btn">
				<button class="btn_i" type="default" @click="btn">故障处理</button>
			</view>
		</view>
		<view class="tabs">
			<u-subsection :list="list" mode="subsection" :current="current" @change="change"></u-subsection>
		</view>
		<view class="wrap">
			<view class="content">
				<view v-if="current === 0">
					<view class="items" v-for="(item,index) in datas" :key="index">
						<item_fault_0 :data=item :info="info" />
					</view>
				</view>
				<view v-if="current === 1">
					<view class="items" v-for="(item,index) in datas" :key="index">
						<item_fault_1 :data=item :info="info" />
					</view>
				</view>
				<u-loadmore :status="status" :loadmoreText="loadmoreText" @loadmore="loadmore" />
			</view>
		</view>
	</view>
</template>

<script>
	import item_fault_0 from '../../components/item_fault/item_fault_0.vue'
	import item_fault_1 from '../../components/item_fault/item_fault_1.vue'
	import {
		findSiteTask
	} from '@/api/common.js';
	export default {
		components: {
			item_fault_0,
			item_fault_1
		},
		data() {
			return {
				list: ['待处理', '已处理'],
				current: 0,
				info: {},
				datas: [],
				status: 'loadmore',
				loadmoreText: '点击加载更多',
				page: 0,
				pageCount: 10,
				show_btn: true, //显示处理按钮
			}
		},
		onLoad: function(option) {
			console.log("onLoad:" + option.info)
			this.info = JSON.parse(option.info)
		},
		onShow() {
			this.datas = []
			this.findSiteTask()
		},
		onReachBottom() {
			this.status = 'loading';
			console.log('触发上拉加载：' + this.status)
			this.page++;
			this.findSiteTask()
		},
		methods: {
			btn() {
				uni.navigateTo({
					url: '/pages/fault_treatment/fault_treatment_add?info=' + JSON.stringify(this.info)+'&op=1'
				})
			},
			findSiteTask() {
				var progress = 'DC7E2F75-CED9-4316-951C-E12981AB3A19' //未处理
				if (this.current == 1) {
					// 	var progress = 'C6D2925A-8E90-44CA-A735-20B08DCB63B2' //处理中
					// } else if (this.current == 2) {
					var progress = '0A29EE48-55F6-45D8-831D-8B8125AC88F9' //处理完成
				}
				findSiteTask({
					progress: progress,
					siteid: this.info.id,
					pageSize: this.pageCount,
					page: this.page
				}).then(res => {
					if (res.records.length > 0) {
						this.datas.push.apply(this.datas, res.records);
					}
					if (res.hasNext == false) {
						this.status = 'nomore';
					}
				}).catch(err => {
					console.log(err);
					uni.showToast({
						title: err,
						icon: 'none'
					});
				})
			},
			change(index) {
				this.current = index
				this.status = 'loadmore'
				this.loadmoreText = '点击加载更多'
				this.page = 0
				this.datas = []
				this.findSiteTask()
			},
			loadmore() {
				console.log('触发加载：' + this.status)
				this.page++;
				this.findSiteTask()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {}

	.name2 {
		height: 120rpx;
		width: 84vw;
		@include flex();
		margin-bottom: 4vh;

		.name2_1 {
			color: $font-color;
			font-size: 40rpx;
			width: 100vw;
			text-align: center;
		}
	}

	.content {
		margin-top: 32rpx;

		.items {}
	}

	.btn {
		width: 280rpx;

		.btn_i {
			height: 68rpx;
			background-color: $bg-color;
			border-color: $bg-color;
			border-radius: 8rpx;
			color: white;
			font-size: 24rpx;
			text-align: center;
		}
	}
</style>